//
//  M1ShopViewController.m
//  NewMarryU
//
//  Created by apple on 2018/8/1.
//  Copyright © 2018年 Cedar. All rights reserved.
//

#import "M1ShopViewController.h"
#import "M1ShopDetailViewController.h"
@interface M1ShopViewController ()<UIWebViewDelegate>
@property (nonatomic ,strong) UIWebView *m1_webView;
@end

@implementation M1ShopViewController
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"商城";
    if (!_m1_webView) {
        _m1_webView = [[UIWebView alloc]init];
        _m1_webView.delegate = self;
        [self.view addSubview:_m1_webView];
        
        [_m1_webView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_offset(UIEdgeInsetsMake(m1_NAV_HEIGHT, 0, 0, 0));
        }];
    }
    if (@available(iOS 11.0, *))
    {
        _m1_webView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }else{
        self.automaticallyAdjustsScrollViewInsets = NO;
        
    }
    
    NSString *urlString = @"http://h5.xiake99.com/Store/storeIndex?app=mu";
    NSString* encodedString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    [_m1_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:encodedString]]];
    
}
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
    if (![request.URL.absoluteString isEqualToString:@"http://h5.xiake99.com/Store/storeIndex?app=mu"]) {
        NSString *requestStr = [[request.URL absoluteString] stringByRemovingPercentEncoding];
        M1ShopDetailViewController *detail = [[M1ShopDetailViewController alloc]init];
        detail.hidesBottomBarWhenPushed = YES;
        detail.m1_url = requestStr;
        [self.navigationController pushViewController:detail animated:YES];
        return NO;
    }
    
    return YES;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
